package com.foo.DAOtest;

import static org.junit.Assert.*;

import java.util.List;


import org.sjsusearch.www.restaurantservice.RestaurantList;
import org.junit.Before;
import org.junit.Test;
import org.sjsusearch.www.restaurantservice.Restaurant;
import org.restaurantexample.ws.RestaurantDAO;
import org.restaurantexample.ws.ServiceUnavailableException;

public class RestaurantDAOTestCases {

	public RestaurantDAO retaurantDAO = new RestaurantDAO();
	
	@Test
	public void testGetAllRestaurantData() throws ServiceUnavailableException {
		try 
		{
			RestaurantList allData =  retaurantDAO.getAllRestaurantData();
			if(allData != null)
			{
				assertEquals(50, allData.getRestaurantList().length);
			}
			else
			{
				assertNotNull(allData);
			}
		} 
		catch (ServiceUnavailableException e) {
			fail("Get All Data testcase failed");
		}
	}

	@Test
	public void testGetRestaurantByName() {
		try 
		{			
			Restaurant specificRestaurant =  retaurantDAO.getRestaurantByName("Acapulco");
			if(specificRestaurant != null)
			{
				assertEquals("Acapulco", specificRestaurant.getRestaurant_name());
			}
			else
			{
				assertNotNull(specificRestaurant);
			}
		} 
		catch (ServiceUnavailableException e) {
			fail("Get All Data testcase failed");
		}
	}

	@Test
	public void testGetRestaurantByCusine() {
		try 
		{
			RestaurantList restaurantByCusine =  retaurantDAO.getRestaurantByCusine("Indian");
			if(restaurantByCusine != null)
			{
				assertEquals(11, restaurantByCusine.getRestaurantList().length);
			}
			else
			{
				assertNotNull(restaurantByCusine);
			}	
			restaurantByCusine =  retaurantDAO.getRestaurantByCusine("Chinese");
			if(restaurantByCusine != null)
			{
				assertEquals(4, restaurantByCusine.getRestaurantList().length);
			}
			else
			{
				assertNotNull(restaurantByCusine);
			}
			
			restaurantByCusine =  retaurantDAO.getRestaurantByCusine("Italian");
			if(restaurantByCusine != null)
			{
				assertEquals(6, restaurantByCusine.getRestaurantList().length);
			}
			else
			{
				assertNotNull(restaurantByCusine);
			}
			
			restaurantByCusine =  retaurantDAO.getRestaurantByCusine("Mexican");
			if(restaurantByCusine != null)
			{
				assertEquals(3, restaurantByCusine.getRestaurantList().length);
			}
			else
			{
				assertNotNull(restaurantByCusine);
			}
		} 
		catch (ServiceUnavailableException e) {
			fail("Get All Data testcase failed");
		}
	}

	@Test
	public void testGetRestaurantByRating() {
		try 
		{
			RestaurantList restaurantByRating =  retaurantDAO.getRestaurantByRating(3.5);
				if(restaurantByRating != null)
				{
					assertEquals(1, restaurantByRating.getRestaurantList().length);
				}
				else
				{
					assertNotNull(restaurantByRating);
				}
				restaurantByRating =  retaurantDAO.getRestaurantByRating(4.5);
				if(restaurantByRating != null)
				{
					assertEquals(20, restaurantByRating.getRestaurantList().length);
				}
				else
				{
					assertNotNull(restaurantByRating);
				}
				
				restaurantByRating =  retaurantDAO.getRestaurantByRating(4.0);
				if(restaurantByRating != null)
				{
					assertEquals(15, restaurantByRating.getRestaurantList().length);
				}
				else
				{
					assertNotNull(restaurantByRating);
				}
				
				restaurantByRating =  retaurantDAO.getRestaurantByRating(5.0);
				if(restaurantByRating != null)
				{
					assertEquals(14, restaurantByRating.getRestaurantList().length);
				}
				else
				{
					assertNotNull(restaurantByRating);
				}
		} 
		catch (ServiceUnavailableException e) {
			fail("Get All Data testcase failed");
		}
	}

}
